﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.Core.Modelling.Primitives;
using ITAP.Core.Modelling;

namespace ITAP.ShprossesBuilder.Modelling.Measurement
{
    public class PinHolesDimension : SizeDimension
    {
        private bool considerAsSizeDimension = true;

        public bool ConsiderAsSizeDimension
        {
            get { return considerAsSizeDimension; }
            set { considerAsSizeDimension = value; }
        }

        private string text;
        public override string Text
        {
            get
            {
                return text;
            }
        }

        public PinHolesDimension(IEndedPrimitive primitive)
            : base(primitive)
        {
        }

        public PinHolesDimension(IEndedPrimitive primitive, string text)
            : this(primitive)
        {
            this.text = text;
        }

        public override void AcceptVisitor(IDimensionVisitor visitor)
        {
            visitor.Visit(this);
        }

        public override bool IsCollide(Dimension other)
        {
            if (considerAsSizeDimension && this.primitive.Height == 0)
                return base.IsCollide(other);

            if (!(other is PinHolesDimension))
                return false;
            else
            {
                if ((this.Side == other.Side) && this.Level == other.Level && 
                    (this.Primitive.IsPointInSegment(other.Primitive.StartPoint, true) && 
                     this.Primitive.IsPointInSegment(other.Primitive.EndPoint, true)))
                    return true;
                else
                    return false;
            }
        }

        public override bool Equals(Dimension other)
        {
            if (considerAsSizeDimension)
                return base.Equals(other);

            if (!(other is PinHolesDimension))
                return false;
            else
            {
                return base.Equals(other);
            }
        }

        public override object Clone()
        {

            PinHolesDimension clone = new PinHolesDimension((IEndedPrimitive)this.Primitive.Clone(), this.Text);
            clone.Level = this.level;
            clone.side = this.side;            
            clone.InitialStartPoint = (ModelPoint)this.InitialStartPoint.Clone();
            clone.InitialEndPoint = (ModelPoint)this.InitialEndPoint.Clone();
            clone.ConsiderAsSizeDimension = this.ConsiderAsSizeDimension;
            return clone;
        }
    }
}
